#include "AABB.h"

AABB::AABB(vector3<float> _start, vector3<float> _end)
:start(_start), end(_end)
{
    center = (start+end)/2;
}

bool AABB::hasContactedAABB(vector3<float> _start, vector3<float> _end){
    if(end.x < _start.x || start.x > _end.x)return false;
    if(end.y < _start.y || start.y > _end.y)return false;
    if(end.z < _start.z || start.z > _end.z)return false;
    return true;
}

bool AABB::hasContactedAABB(AABB &box){
    vector3<float>& _start = box.start;
    vector3<float>& _end = box.end;

    if(end.x < _start.x || start.x > _end.x)return false;
    if(end.y < _start.y || start.y > _end.y)return false;
    if(end.z < _start.z || start.z > _end.z)return false;
    return true;
}

vector3<float> AABB::getCorrection(vector3<float> _start, vector3<float> _end){
    vector3<float> corrected(0,0,0);

    if(end.x > _start.x && end.x < _end.x) corrected.x = _start.x-end.x;
    else corrected.x = start.x - _end.x;
    if(end.y > _start.y && end.y < _end.y) corrected.y = _start.y-end.y;
    else corrected.y = start.y - _end.y;
    if(end.z > _start.z && end.z < _end.z) corrected.z = _start.z-end.z;
    else corrected.z = start.z - _end.z;

    return corrected;
}



bool AABB::hasContactedWorld(){
    return false;
}
